package com.cykj.utils;



import com.auth0.jwt.JWT;
import com.auth0.jwt.algorithms.Algorithm;

import java.util.Date;

public class TokenUtils {
    public static String createToken(String acc,String pwd){//登录成功时候调用
        Date start = new Date();
        long currentTime = System.currentTimeMillis() + 60 * 1000 * 10;
        Date end = new Date(currentTime);
        String token = JWT.create().withAudience(acc).withIssuedAt(start).withExpiresAt(end).sign(Algorithm.HMAC256(pwd));
        return token;
    }

    public static String getTokenUserId(String token){//网关鉴权时调用
        String userId  = JWT.decode(token).getAudience().get(0);
        return userId;
    }

}
